﻿
/**
* <p><b>CommandTemplate is a base class for commands. Deprecated as of Arp 2.1</b></p> 
* 
* All this base class does is save a reference to the viewRef when its 
* execute() method is called and then calls the executeOperation() primitive 
* operation as a hook. 
* 
* The functionality provided by the CommandTemplate class is limited and use
* of this class is discouraged. You can simplycreate your own Command classes 
* without extending it. (Just remember to save a reference to the event
* source in your command if it executes asynchronous business logic.)
*
* <p><i>Copyright &copy; 2004-2006 <a href="http://flashant.org">Aral Balkan</a>.
* Arp lives at <a href="http://osflash.org/arp">http://osflash.org/arp</a>. 
* 
* Released under the open-source MIT license.
* (http://www.opensource.org/licenses/mit-license.php)
* See license.txt for full license terms.</i></p>
*/
class org.osflash.arp.CommandTemplate
{
	//////////////////////////////////////////////////////////////////////
	//
	// Properties
	//
	//////////////////////////////////////////////////////////////////////

	/**
	* If the ConcreteCommand uses a Business Delegate, it should define it
	* as a member property here.
	*/
	
	/**
	* Reference to the view for this command. This is *not* strongly typed on
	* purpose since we don't know the exact type of the view even at runtime
	* (Flash doesn't provide much in the way introspection.)
	*/
	var viewRef;	

	
	//////////////////////////////////////////////////////////////////////
	//
	// Constructor
	//
	//////////////////////////////////////////////////////////////////////
	function Command ()
	{
		// nothing
	}
	
	//////////////////////////////////////////////////////////////////////
	//
	// Primitive operations (*must* be overriden)
	//
	//////////////////////////////////////////////////////////////////////
	
	/**
	* ConcreteCommand classes have to override the executeOperation method 
	* with their command behavior. This is called by the concrete execute()
	* method.
	*/
	private function executeOperation ()
	{
		throw new Error (
			"ERROR Command did not implement primitive operation"
			+" executeOperation(). No behavior defined for command."
		);
	}


	////////////////////////////////////////////////////////////////////////////
	//
	// Hook operations (ConcreteCommands are *not* required to override these
	// but may do so if they wish.)
	//
	////////////////////////////////////////////////////////////////////////////
	
	// None
	
	////////////////////////////////////////////////////////////////////////////
	//
	// Group: Concrete operations
	//
	////////////////////////////////////////////////////////////////////////////

	/**
	* Saves a reference to the event source and calls the executeOperation 
	* primitive operation which you must override to carry out actual 
	* business logic.
	* 
	* @param	viewRef	Reference to the event source. Untyped on purpose.
	*/
	public function execute ( viewRef )
	{
		// save view reference
		this.viewRef = viewRef;
		
		// primitive operation
		executeOperation();
	}

	// 
	// Note: The onStatus and onResult methods have been removed as they were
	// biased towards remote method calls.
	//
}
